PATHMac OS 8 and 9 Developer Documentation > Interapplication Communication > AppleScript for Scripters >

AppleScript Language Guide

   

Styled Text

The class identifier Styled Text is a synonym for a string that includes style and font information.

LITERAL EXPRESSIONS

The only difference between a value of class String and a value of class Styled Text is that the latter can include (but is not required to include) style and font information. Thus any valid literal expression of class String is also valid as class Styled Text.

PROPERTIES
Class
The class identifier for the object. This property is read-only, and its value is always string .
Length
The number of characters in the string.
ELEMENTS

Styled text has the same character, word, paragraph, and text elements as a string.

OPERATORS

Because values identified as Styled Text values are really values of class String, the operators available are the operators described in the definition of class String: & , = , , > , , < , , Starts With, Ends With, Contains, Is Contained By, and As.

For detailed explanations and examples of how AppleScript operators treat strings, see Operators That Handle Operands of Various Classes.

REFERENCE FORMS

You can use the same reference forms with styled text that you can use with strings: Property, Index, Middle, Arbitrary, Every Element, and Range. For details, see String.

SPECIAL CHARACTERS AND STRING CONSTANTS

You can use the same special characters, constants, and coercions with styled text that you can use with strings. For details, see String. Note that literal string constants do not include style and font information; in other words, they are not styled text.

COERCIONS SUPPORTED

You can use the same coercions with styled text that you can use with strings: coercion to an integer, number, real number, or single-item list, and coercion of a list of strings to a single concatenated string.

You can use the class identifier Styled Text to coerce any string to styled text. However, the resulting value is always of class String.

NOTES

AppleScript itself provides no commands for directly manipulating styled text. To change the style or font information for a styled text value, you must work with an application that knows how to manipulate styled text. However, AppleScript does preserve style and font information when copying text objects from applications to scripts and vice versa.

For example, you can use a script like this to obtain styled text, manipulate it, and copy it back into an AppleWorks document:

tell application "AppleWorks"
    -- Get text from open document.
    set myText to text body of document "Report"
    -- Add some information at the end.
    set myText to myText & return & "The End."
    -- Select all the current text in the document and replace it.
    select text body of document "Report"
    set selection of document "Report" to myText
    close document "Report" saving ask
end tell

Because AppleWorks returns styled text when it returns the text from a document, you don't need to coerce the returned text to styled text. The style and font of the text are preserved both when it is copied to the variable myText and when it is concatenated with a return character and the string "The End." The modified text that is inserted back into the document consists of the original text with its original style and font, a return character to move to a new line, and the unstyled text, "The End.", which appears in the style and font of the text immediately preceding it.

Styled text also contains information about the form in which the text is written. If you copy non-Roman text to a variable in a script as styled text, AppleScript preserves the original text information even though the Script Editor may not be able to display it correctly. If you then copy the text to an application that can handle the text in its original form, the text is displayed correctly. For related information, see Unicode Text and International Text.


© 1999 Apple Computer, Inc. – (Last Updated 21 May 99)